<!--Generate by Kevin's CodeBuilder -->
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
		<meta charset="UTF-8">
		<title>工作流管理系统</title>
		<head  th:replace="source::header"></head>
</head>
<body>
		<div id="k_page_erea" class="form_main_wrap">
			<div class="k_form_grid">
				<table id="datagrid"></table>
			</div>
			<div class="k_form_condition"  style="padding:12px 14px;">
				<table class="k_form_table" id="k_form_query_wrap">
					<tr>
						<td class="label label100">菜单名称</td>
						<td>
							<input id="menuText" name="menuText" placeholder="菜单名称" style="width: 300px;" class="form_input" type="text"/>
							<span style="padding-left:30px">
								<button class="k_common_button" id="search_btn">
									<i class="fa fa-search"></i>
									[(${Lang.common_search})]
								</button>
							</span>
						</td>
					</tr>
				</table>
			</div>
		</div>
</div>
<script type="application/javascript" th:inline="javascript">
		var curdObj,
			height = 500,
			gridOpts = [(${dataGridJson})];//获取datagrid配置json
			var title = "[(${Lang.menu_windowTitle})]";//国际化语言
			gridOpts.title = title;

		$B.DomUtils.onDomLoaded(function () {
			var dg =  document.getElementById("datagrid");
			gridOpts.setParams = function(){
				return {pid:0};
			};
			gridOpts.title = "";
			gridOpts.pageArea = "k_page_erea";
			gridOpts.fit2height = true;
			//gridOpts.idField = "id";
			gridOpts.sortField = {"orderIndex" : "asc"};
			gridOpts.oprColWidth = 120;

			curdObj = new $B.CURD(dg, gridOpts);
			//输入框绑定清理按钮
			$B.bindInputClear("k_form_query_wrap");

			$B.DomUtils.click(document.getElementById("search_btn"),()=>{
					var text = document.getElementById("menuText").value;
					curdObj.reload({
						pid:0,
						text:text
					});
			});
		});
		//打开form.html
		function _openForm(prs,isUpdate,winTitle){
			console.log(prs,isUpdate);
			var opts = {
				dataType:'html',
				title:winTitle ? winTitle:title,
				width:750,
				height:height
			};
			if(prs){
				opts.params = prs;
			}
			curdObj.window(opts,isUpdate);
		};
		/******工具栏事件集合******/
		window.tableMethods = {
			addFn:function(prs){
				_openForm({pid:'0'},false,'[(${Lang.common_add_title})]');
			},
			updateFn:function(prs){
				_openForm(undefined,true,'[(${Lang.common_update_title})]');
			},
			deleteFn:function(prs){
				curdObj.delChecked();
			},
			lineUpdateFn:function(prs){
				_openForm({id:prs.id},true,'[(${Lang.common_update_title})]');
			},
			lineDeleteFn:function(prs){
				curdObj.deleteData([prs.id]);
			},
			treeFn:function(prs){
				var opts = {
					dataType:'iframe',
					title:title+"["+prs.menuText+"]",
					// full:true,
					width:'70%',
					height:'85%',
					url: $B.getHttpHost(ctxPath) + "menu/page/tree?pid="+prs.id
				};
				$B.window(opts);
			}
		};

		/***格式化***/
		function formatLeaf(cellData,rowData){
			if(cellData === 1){
				return "[(${Lang.common_yes})]";
			}
			return "[(${Lang.common_no})]";
		}  

		function switchEnable(name,val,oldVal,oldClazz){
			let childs = $B.DomUtils.children(this,"span");
			let $input = this.lastChild;
			let id =  $B.DomUtils.attribute($input,"dataid");
			$B.request({
				waiting:true,
				url : $B.getHttpHost(ctxPath) + "menu/status",
				data:{id:id,status:val},
				fail:function (msg,data) {
					for(let i =0 ; i < childs.length ; i++){
						$B.DomUtils.attribute(childs[i],oldClazz[i]);
					}
					$input.value = oldVal;
					$B.error(msg,1.5);
				},
				ok:function () {
					$B.success("修改成功！",1.6);
				}
			});
		}

		function formatEnable(cellData,rowData){
			let $wap = this.firstChild.firstChild;
			let $in = $B.DomUtils.createEl('<input dataid="'+rowData.id+'" id="mstatus" name="mstatus" value="'+cellData+'" type="hidden">');
			$B.DomUtils.append($wap,$in);
			$B.switchCtl( $in,{
				notReturn:true,
			    onChange:switchEnable
			});
			return false;
		}  
		function formatVisible(cellData,rowData){
			if(cellData === 1){
				return "[(${Lang.common_yes})]";
			}
			return "[(${Lang.common_no})]";
		}
</script>
</body>
</html>
